{php include wl_template('common/header');}

<ul class="nav nav-tabs">

    <li{if $op == 'display'} class="active"{/if}>
        <a href="{php echo web_url('service/workbook_submit', array('op' => 'dispaly'))}">目录管理</a>
    </li>
</ul>
<div class="clearfix">
{if $op == 'display'}
	
	
	<div class="panel panel-default">
		<form class="form form-horizontal" action="" method="post" role="form" id="form1">
		<input type="hidden" name="c" value="site" />
        <input type="hidden" name="a" value="entry" />
        <input type="hidden" name="m" value="lexiangpingou" />
        <input type="hidden" name="do" value="service" />
        <input type="hidden" name="ac" value="workbook_submit" />
        <input type="hidden" name="op" value="add_first" />
			<div class="panel-body" style="margin-top: 40px;">
				<div class="form-group">
					<label class="col-md-2 control-label"  style="padding: 5px; text-align: center;">一级目录:</label>
					<div class="col-md-6">
						<input type="text" name="first_directory" class="form-control" id="first_directory" value=""  autocomplete="off" />
					</div>
					<div class="col-md-4">
						<input type="submit" name="button" value="添加一级目录" class="btn btn-primary " />
					</div>
				</div>
			</div>
		</form>
	
		<div class="panel-body table-responsive">
			<table class="table table-hover">
				<thead class="navbar-inner">
					<tr>

						<th style="width:8%">排序</th>
						<th style="width:11%">目录级别</th>
						<th style="width:25%">一级目录</th>
						<th style="width:25%">二级目录</th>
						<th style="width:31%;text-align: center;">操作</th>	

					</tr>
				</thead>
				<tbody>
				{loop $directory_f $first}
				<tr>
					<td><input id="first_sort" onchange="sort_first(this.value,'{$first['id']}')" type="text" class="form-control" value="{$first['sort']}"/></td>
					<td>一级</td>
					<td><input id="first_directory" style="text-align: center; font-weight: bold;" onchange="changename_first(this.value,'{$first['id']}')" type="text" class="form-control" value="{$first['first_directory']}"/></td>
					<td></td>
					<td style="text-align: left;">
						<a class="btn btn-default btn-xs" href="{php echo web_url('service/workbook_submit',array('op' => 'edit_first','id' => $first['id']))}" style="margin-right: 10px;">编辑该页面</a>
						<a class="btn btn-primary btn-xs" onclick="new_second('{$first['id']}')" style="margin-right: 10px;">添加子目录</a>
						<a onclick="return check();" class="btn btn-warning btn-xs" href="{php echo web_url('service/workbook_submit',array('op' => 'delete_first','id' => $first['id']))}">删除该目录</a>
					</td>
				</tr>
				<?php 
					$directory_s = pdo_fetchall("select id,first_id,second_directory,url,sort from ".tablename('workbook_directory_second')." where  first_id=:first_id order by  sort desc , id",array(':first_id'=>$first['id']));
				?>
				{loop $directory_s $second}
				<tr style="background: ;">
					<td><input id="second_sort" onchange="sort_second(this.value,'{$second['id']}')" type="text" class="form-control" value="{$second['sort']}"/></td>
					<td>二级</td>
					<td >
						<select onchange="change_father(this.value,'{$second['id']}')" class="form-control" style="text-align: center;">
	                            <option style="text-align: center; "  value="{$first['id']}">{$first['first_directory']}</option>
	                            <?php 
									$directory_f_select = pdo_fetchall("select id,first_directory from ".tablename('workbook_directory_first')." where id <> :id order by sort desc",array(':id' => $first['id']));
								?>
	                            {loop $directory_f_select $first_title}
	                            <option value="{$first_title['id']}" >{$first_title['first_directory']}</option>
	                            {/loop}
	                    </select>
					</td>
					<td><input id="gorder" style="text-align: center;" onchange="changename_second(this.value,'{$second['id']}')" type="text" class="form-control" value="{$second['second_directory']}"/></td>
					<td style="text-align: left;">
						<a class="btn btn-default btn-xs" href="{php echo web_url('service/workbook_submit',array('op' => 'edit','id' => $second['id']))}" style="margin-right: 10px;">编辑该页面</a>
						<a onclick="return check();" class="btn btn-warning btn-xs" href="{php echo web_url('service/workbook_submit',array('op' => 'delete_second','id' => $second['id']))}">删除该目录</a>
					</td>
				</tr>
				{/loop}
				{/loop}
				</tbody>
			</table>
		</div>
	</div>

<script>
	function new_second(id){

		$("#img_show").html('<input type="hidden" name="first_id" value="'+id+'" />'); 
		$('#modal-module-add').modal();
	}
	function check(){
		if(confirm("是否确定删除该目录？注：父目录删除时请确保没有子目录，否则子目录将不再显示！")){ 
			return true; 
		}else{ 
			return false; 
		} 
	}
	function sort_first(str,id)
	{  	
		var sort = str; 
		var id = id;
		$.ajax({
	             type: "GET",
	             url: "{php echo web_url('service/workbook_submit',array('op' => 'sort_first'))}",
	             data:{"id":id,"sort":sort},
				 dataType: "json",
	             success: function(data){	
					util.tips('排序已改变！', 2000);
					setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
					window.location.reload();//页面刷新
					},1000);
					
				 }
	         });

	}
	function sort_second(str,id)
	{  	
		var sort = str; 
		var id = id;
		$.ajax({
	             type: "GET",
	             url: "{php echo web_url('service/workbook_submit',array('op' => 'sort_second'))}",
	             data:{"id":id,"sort":sort},
				 dataType: "json",
	             success: function(data){	
					util.tips('排序已改变！', 2000);
					setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
					window.location.reload();//页面刷新
					},1000);
					
				 }
	         });

	}
	function changename_first(str,id)
	{
		
		var name = str; 
		var id = id;
		$.ajax({
	             type: "GET",
	             url: "{php echo web_url('service/workbook_submit',array('op' => 'changename_first'))}",
	             data:{"id":id,"name":name},
				 dataType: "json",
	             success: function(data){	
					util.tips('目录名称已改变！', 2000);
					setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
					window.location.reload();//页面刷新
					},1000);
					
				 }
	         });
	}
	function changename_second(str,id)
	{
		var name = str; 
		var id = id;
		$.ajax({
	             type: "GET",
	             url: "{php echo web_url('service/workbook_submit',array('op' => 'changename_second'))}",
	             data:{"id":id,"name":name},
				 dataType: "json",
	             success: function(data){	
					util.tips('目录名称已改变！', 2000);
					setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
					window.location.reload();//页面刷新
					},1000);
					
				 }
	         });
	}
	function change_father(str,id)
	{
		var fid = str; 
		var id = id;
		$.ajax({
	             type: "GET",
	             url: "{php echo web_url('service/workbook_submit',array('op' => 'change_father'))}",
	             data:{"id":id,"fid":fid},
				 dataType: "json",
	             success: function(data){	
					util.tips('父级从属已改变！', 2000);
					setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
					window.location.reload();//页面刷新
					},1000);
					
				 }
	         });
	}
	
</script>
<div id="modal-module-add" class="modal fade sc" tabindex="-1">
	<div class="modal-dialog" style='width:1000px; height:200px;font-size: 14px; margin-top:14%; text-align: left; padding: 30px; '>
		<form class="form form-horizontal" action="" method="post" role="form" id="form1">
		<input type="hidden" name="c" value="site" />
        <input type="hidden" name="a" value="entry" />
        <input type="hidden" name="m" value="lexiangpingou" />
        <input type="hidden" name="do" value="service" />
        <input type="hidden" name="ac" value="workbook_submit" />
        <input type="hidden" name="op" value="add_second" />
			<div class="modal-content" style=" padding: 30px; ">
				<div id="img_show" style=""></div>
				<div class="panel-body">
						<div class="form-group">
							<label class="col-md-2 control-label" >二级目录:</label>
							<div class="col-md-6">
									<input type="text" name="second_directory" class="form-control" id="second_directory" value=""  autocomplete="off" />
							</div>
	
						</div>
				</div>

				<div style="text-align: center;">
					<input type="submit" name="submit" value="添加" class="btn btn-primary" />
					<input type="button" class="btn btn-primary" value="取消" data-dismiss="modal" />

				</div>
				
			</div>
		</form>
	</div>
</div>
{/if}

{if $op == 'edit'}
	<form class="form form-horizontal" action="" method="post" role="form" id="form1">
		<input type="hidden" name="c" value="site" />
            <input type="hidden" name="a" value="entry" />
            <input type="hidden" name="m" value="lexiangpingou" />
            <input type="hidden" name="do" value="service" />
            <input type="hidden" name="ac" value="workbook_submit" />
            <input type="hidden" name="op" value="publish" />
		<div class="panel panel-default">
			<div class="panel-heading">
				发布操作手册
			</div>
			<div class="panel-body">
					<div class="form-group">
						<label class="col-xs-12 col-sm-3 col-md-2 control-label" style="display: none;">id:</label>
						<div class="col-sm-6 col-xs-12" style="position:relative;display: none;">
								<input type="text" name="id" class="form-control" id="id" value="{$content['id']}"  autocomplete="off" />
						</div>
						<label class="col-xs-12 col-sm-3 col-md-2 control-label">当前目录:</label>
						<div class="col-sm-6 col-xs-12" style="position:relative">
								<label class="control-label">{$content['second_directory']}</label>
						</div>
					</div>
					<div class="form-group">
						<label class="col-xs-12 col-sm-3 col-md-2 control-label">页面内容:</label>
						<div class="col-sm-9 col-xs-12" style="position:relative">
						{php echo tpl_ueditor('content', $content['content']);}
						</div>
					</div>
			</div>
		</div>
		<div class="form-group">
			<div class="col-sm-12">
				<input type="submit" name="submit" value="提交" class="btn btn-primary col-lg-1" />
			</div>
		</div>
	</form>
<script>
$(function(){
		$('#form1').submit(function(){
		if($('input[name="title"]').val() == ''){
				util.message('请填写标题.');
				return false;
		}
		if($('input[name="summary"]').val().length > 4){
				util.message('请填写简介.');
				return false;
		}
		if($('input[name="content"]').val() == ''){
				util.message('请填写内容.');
				return false;
		}
		});
});
</script>
{/if}

{if $op == 'edit_first'}
	<form class="form form-horizontal" action="" method="post" role="form" id="form1">
		<input type="hidden" name="c" value="site" />
            <input type="hidden" name="a" value="entry" />
            <input type="hidden" name="m" value="lexiangpingou" />
            <input type="hidden" name="do" value="service" />
            <input type="hidden" name="ac" value="workbook_submit" />
            <input type="hidden" name="op" value="publish_first" />
		<div class="panel panel-default">
			<div class="panel-heading">
				发布操作手册1
			</div>
			<div class="panel-body">
					<div class="form-group">
						<label class="col-xs-12 col-sm-3 col-md-2 control-label" style="display: none;">id:</label>
						<div class="col-sm-6 col-xs-12" style="position:relative;display: none;">
								<input type="text" name="id" class="form-control" id="id" value="{$first['id']}"  autocomplete="off" />
						</div>
						<label class="col-xs-12 col-sm-3 col-md-2 control-label">当前目录:</label>
						<div class="col-sm-6 col-xs-12" style="position:relative">
								<label class="control-label">{$first['first_directory']}</label>
						</div>
					</div>
					<div class="form-group">
						<label class="col-xs-12 col-sm-3 col-md-2 control-label">页面内容:</label>
						<div class="col-sm-9 col-xs-12" style="position:relative">
						{php echo tpl_ueditor('content', $first['content']);}
						</div>
					</div>
			</div>
		</div>
		<div class="form-group">
			<div class="col-sm-12">
				<input type="submit" name="submit" value="提交" class="btn btn-primary col-lg-1" />
			</div>
		</div>
	</form>
<script>
$(function(){
		$('#form1').submit(function(){
		if($('input[name="title"]').val() == ''){
				util.message('请填写标题.');
				return false;
		}
		if($('input[name="summary"]').val().length > 4){
				util.message('请填写简介.');
				return false;
		}
		if($('input[name="content"]').val() == ''){
				util.message('请填写内容.');
				return false;
		}
		});
});
</script>
{/if}

</div>



{php include wl_template('common/footer');}